summaryrefslogtreecommitdiff
path: root/src/pages/api/formdata/[slug].ts
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-05-15 15:50:51 +0700
committerpolwex <polwex@sortug.com>2025-05-15 15:50:51 +0700
commit05d13b6f166eae5c2de8fe6f6038819b1b6ba1a0 (patch)
tree795ca33a3319d11bd9daa0366d4d15f31eabf024 /src/pages/api/formdata/[slug].ts
parent92139f14a92a535f123ad49a60498138dd2ec6cf (diff)
m
Diffstat (limited to 'src/pages/api/formdata/[slug].ts')
-rw-r--r--src/pages/api/formdata/[slug].ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/pages/api/formdata/[slug].ts b/src/pages/api/formdata/[slug].ts
new file mode 100644
index 0000000..3580e6a
--- /dev/null
+++ b/src/pages/api/formdata/[slug].ts
@@ -0,0 +1,50 @@
+// import db from "../../lib/db";
+import { NLP } from "sortug-ai";
+
+type Req = { endpoint: "nlp" | "llm"; app: string; body: any };
+export const POST = async (request: Request): Promise<Response> => {
+ const url = URL.parse(request.url);
+ const path = url!.pathname.replace("/api/formdata", "");
+ const body = await request.formData();
+ if (path === "/ocr") return postOCR(body);
+ // TODO audio etc. a lot of stuff goes through here
+
+ // if (!body.name || !body.creds) {
+ return Response.json({ message: "Invalid" }, { status: 400 });
+ // }
+
+ // try {
+ // const res = db.loginUser(body.name, body.creds);
+ // console.log({ res });
+
+ // return Response.json(res, { status: 200 });
+ // } catch (error) {
+ // return Response.json({ message: "Failure" }, { status: 500 });
+ // }
+};
+export const GET = async (request: Request): Promise<Response> => {
+ console.log({ request });
+
+ // if (!body.name || !body.creds) {
+ return Response.json({ message: "Invalid" }, { status: 400 });
+ // }
+
+ // try {
+ // const res = db.loginUser(body.name, body.creds);
+ // console.log({ res });
+
+ // return Response.json(res, { status: 200 });
+ // } catch (error) {
+ // return Response.json({ message: "Failure" }, { status: 500 });
+ // }
+};
+
+async function postOCR(formData: FormData) {
+ try {
+ const res = await NLP.ocr(formData);
+ console.log({ res });
+ return Response.json(res, { status: 200 });
+ } catch (error) {
+ return Response.json({ message: "Failure" }, { status: 500 });
+ }
+}